package com.fancy.projecty.controller;

import com.fancy.projecty.pojo.WaterAgent;
import com.fancy.projecty.service.WaterAgentService;
import com.fancy.projecty.util.SuccessVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;


/**
 * 代理商管理
 * 代理商权限可以访问
 */
@RequestMapping("/waterAgent")
@RestController
@CrossOrigin
@Api(tags = "代理商管理")
public class WaterAgentController {

	@Autowired
	private WaterAgentService waterAgentService;

	@GetMapping("/selectById/{id}")
	public SuccessVo selectById(@PathVariable Integer id) {
		WaterAgent waterAgent = this.waterAgentService.selectById(id);
		return new SuccessVo(waterAgent);
	}

	@ApiOperation(value = "插入", notes = "")
	@PostMapping("/insert}")
	public SuccessVo insert(@RequestBody WaterAgent waterAgent) {
		this.waterAgentService.insert(waterAgent);
		return new SuccessVo();
	}

	@ApiOperation(value = "条件分页查询", notes = "pageNum,pageSize")
	@PostMapping("/selectByPage/}")
	public SuccessVo selectByPage(@RequestBody Map map) {
		PageInfo<WaterAgent> pageInfo = this.waterAgentService.selectByPage(map);
		return new SuccessVo(pageInfo);
	}

	@ApiOperation(value = "修改  或者逻辑删除都可以走这个方法")
	@PutMapping("/updateById/}")
	public SuccessVo updateById(@RequestBody WaterAgent waterAgent) {

		waterAgent.setAgentUpdatetime(new Date());

		this.waterAgentService.updateById(waterAgent);
		return new SuccessVo();
	}


}
